﻿using Clipper.Model;
using Clipper.Model.DataBaseModel;
using Clipper.Model.DetectionModel;
using Global;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//using System.Windows;
using System.Windows.Forms;
//using Clipper.DAL;

namespace Communication
{
    public class ArmMoveControl
    {
        static Clipper.DAL.ReagentKit mReagentKitDal = new Clipper.DAL.ReagentKit();

        public static short Z1MotorID = 65;//Z轴电机id
        public static short Z2MotorID = 65;//Z轴电机id
        public static short XMotorID = 83; //X轴电机id
        public static short YMotorID = 82; //y轴电机id
        public static short Pump1ID = 88;  //泵1id
        public static short Pump2ID = 88;  //泵2id

        public static short Bucket1ID = 88;//水桶反应id1
        public static short Bucket2ID = 88;//水桶反应id2

        public const short RZ1MotorID = 129; //Z轴电机id
        public const short RZ2MotorID = 129; //Z轴电机id
        public const short RXMotorID = 147;  //X轴电机id
        public const short RYMotorID = 146;  //y轴电机id
        public const short RPump1ID = 152;   //泵1id
        public const short RPump2ID = 152;   //泵2id

        public const short RBucket1ID = 152; //水桶id1
        public const short RBucket2ID = 152; //水桶id2

        public static int Z1MotorStatus = 0;//Z1 轴电机状态
        public static int Z2MotorStatus = 0;//Z2 轴电机状态
        public static int XMotorStatus = 0; //X轴电机状态
        public static int YMotorStatus = 0; //Y轴电机状态
        public static int Pump1Status = 0;  //泵1状态
        public static int Pump2Status = 0;  //泵2状态

        public static int BucketStatus = 0; //水桶的状态
        public static int RubbishBucketStatus = 0; //废水桶的状态
        public static int DoorStatus = 0; //门的状态

        public static bool IsPause = false; //臂暂停标志位
        /// <summary>
        /// 样本区 1号 定位 X
        /// </summary>
        public static int x_Axis_Sample = 10600;//样本区坐标  10630
                                                /// <summary>
                                                /// 样本区 1号 定位 Y
                                                /// </summary>
        public static int y_Axis_Sample = 5150;  //5120
        /// <summary>
        /// 样本区 X间距
        /// </summary>
        public static int offSampleSet_x = 628;
        /// <summary>
        /// 样本区 Y间距
        /// </summary>
        public static int offSampleSet_y = 1159;
        /// <summary>
        /// 样本区 Z1的最大下移量
        /// </summary>
        public static int Z1MaxDowndistance = 26000;



        /// <summary>
        /// 制冷试剂区 X初始
        /// </summary>
        public static int x_Axis_Reagent = 14155;//试剂区坐标
        /// <summary>
        /// 制冷试剂区 Y初始
        /// </summary>
        public static int y_Axis_Reagent = 245;
        /// <summary>
        /// 制冷试剂区 X间距
        /// </summary>
        public static int offReagentSet_x = 990;
        /// <summary>
        /// 制冷试剂区 Y间距
        /// </summary>
        public static int offReagentSet_y = 1125;
        /// <summary>
        /// 制冷试剂区 Z2最大的下移量
        /// </summary>
        public static int Z2ReagentMaxDownDistance = 20800;

        /// <summary>
        /// 制冷试剂区 Z1最大的下移量
        /// </summary>
        public static int Z1ReagentMaxDownDistance = 20000;

        /// <summary>
        /// 常温试剂区 X初始
        /// </summary>
        public static int x_Axis_HotReagent = 11000;//常温试剂区
        /// <summary>
        /// 常温试剂区 Y初始
        /// </summary>
        public static int y_Axis_HotReagent = 900;
        /// <summary>
        /// 常温试剂区 X间距
        /// </summary>
        public static int offHotReagent_x = 1250;
        /// <summary>
        /// 常温试剂区 Y间距
        /// </summary>
        public static int offHotReagent_y = 1475;

        /// <summary>
        /// 常温试剂区 Z1轴最大下移量
        /// </summary>
        public static int Z1HotReagentMaxDownDistance = 20000;

        /// <summary>
        /// 常温试剂区 Z2轴最大下移量
        /// </summary>
        public static int Z2HotReagentMaxDownDistance = 20000;


        private static bool ReagentUse = false;



        /// <summary>
        /// 样本针 试剂针 空吸量
        /// </summary>
        /// 
        public static int emptyAsrip = 3000; // 空吸 空气

        public static float SampleFor1UL = 60.0f;
        public static float ReagntFor1UL = 60.0f;

        /// <summary>
        /// 样本针与试剂针偏移量
        /// </summary>
        public static int off_Y_SamplerToReagent = 2200;

        /// <summary>
        /// 检测区 X初始
        /// </summary>
        public static int x_Axis_Detect = 1050;//检测区坐标
                                               /// <summary>
                                               /// 检测区 Y初始
                                               /// </summary>
        public static int y_Axis_Detect = 445;
        /// <summary>
        /// 检测区 X间距
        /// </summary>
        public static int offDetectSet_x = 458;
        /// <summary>
        /// 检测区 Y间距
        /// </summary>
        public static int offDetectSet_y = 2475;
        /// <summary>
        /// 检测区 Z轴最大下移量
        /// </summary>
        public static int Z1DetectMaxDownDistance = 24700;  //更改前位置24700
        /// <summary>
        /// 检测区 Z轴最大下移量
        /// </summary>
        public static int Z2DetectMaxDownDistance = 27000;  //更改前位置 26300

        /// <summary>
        /// 急诊区 X初始
        /// </summary>
        public static int x_Axis_Emergency = 10630;//急诊区 暂用的
                                                   /// <summary>
                                                   /// 急诊区 Y初始
                                                   /// </summary>
        public static int y_Axis_Emergency = 512;
        /// <summary>
        /// 急诊区 X间距
        /// </summary>
        public static int offEmergencySet_x = 628;
        /// <summary>
        /// 急诊区 Y间距
        /// </summary>
        public static int offEmergencySet_y = 1159;

        /// <summary>
        /// 急诊区 Z轴最大下移量
        /// </summary>
        public static int Z1EmergencyMaxDownDistance = 15000;

        /// <summary>
        /// 初始化时的清洗时间
        /// </summary>
        public static int InitCleanTime = 5000;
        //下降距离是 设定
        public static int clearDistance = 16000;

        public static int x_Axis_CleanArea = 9460;  // 清洗区的x轴坐标
        public static int y_Axis_CleanArea = 1280;  // 清洗区y轴坐标


        //检测位1的变量
        public static int detect1Variable = 400;
        //检测位23的变量
        public static int detect23Variable = 400;
        //检测位4的变量
        public static int detect4Variable = 400;

        //c初始化定时器的产生
        static System.Timers.Timer rubbishWaterTimer;
        static bool through = true;

        static System.Timers.Timer washWaterTimer;  //清洗液时间
        static bool throughFlag = true;

        public static string lastSampleName = "";
        static bool IsSampleAsripe = false;

        public static string lastReagentName = "";
        static bool IsReagentAsripe = false;


        public ArmMoveControl()
        {
        }

        /// <summary>
        /// 等待状态改变（等待某个命令的反馈）
        /// </summary>
        /// <param name="status">状态</param>
        public static void WaitStatus(int mCanId, ref int status)
        {
            int time = 0;
            while (status == 0)
            {


                if (time == 30000)
                {
                    Console.WriteLine(mCanId + "," + "超时");

                }
                else if (time == 60000)
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
                time += 100;
            }
        }

        /// <summary>
        /// 移动方法  进行分配  
        /// </summary>
        public static void MoveDistribution()
        {
            int amount = 0;

            for (int i = 2; i < ServiceProvider.DoTestCount + 1; i++)
            {
                //int Water = 200;
                //吸样
                if (ServiceProvider.SelectedValues.Equals("FIB"))
                {
                    if (i == 4)
                    {
                        break;
                    }
                    //amount = 666 - (i - 2) * 60;  //10微升*66.7  
                    amount = 6666;  //10微升*66.7  
                    MoveSampleNeedleToSampleOrWater(2, amount);
                    amount = amount+(i - 1) * amount;
                    WaterUptake(amount);//吸取稀释液
                }
                else
                {
                    amount = 10000;   //控制吸液的量 
                    MoveSampleNeedleToSampleOrWater(i, amount);
                    WaterUptake(amount * 2);//吸取稀释液
                }

                //吸水 以及其他的配比液
                // Water = Water * (i - 1);

                XMotorStatus = 0;
                YMotorStatus = 0;
                int x_R = x_Axis_Sample + ((i - 1) % 15) * offSampleSet_x;
                int y_R = y_Axis_Sample + ((i - 1) / 15) * offSampleSet_y;
                Move_X_YArmToTarget(x_R, y_R);
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
                //加样
                DilutionSample();
                waitStatus = true;
                //清洗
                MoveArmToClearArea(0, 3000, false);
            }
        }

        /// <summary>
        /// 吸水
        /// </summary>
        public static void WaterUptake(int Water)
        {
            int _Amount = emptyAsrip + Water;
            int _hole = -1;
            int x_R = 0;
            int y_R = 0;
            string detectItemVar = ServiceProvider.SelectedValues;
            // int z_R = Z1EmergencyMaxDownDistance;   //紧急样本区Z1下移高度
            int z_R = 0;          //冷试剂区Z1下移高度

            //_Amount = (int)(emptyAsrip + ServiceProvider.SampleList[0].DetectItemModel.bloodAmount * SampleFor1UL);

            foreach (Clipper.Model.ReagentKit r1 in ServiceProvider.ReagentKitVM.ReagentKitList)   //遍历整个界面有没有水
            {
                if (r1.ReagentID2 != null)
                {
                    if (detectItemVar.Equals("DD") && r1.ReagentID2.Equals("盐溶液") && r1.loadDate2 > (int)Water / 66.7)
                    {
                        _hole = r1.holeNumber;
                        break;
                    }
                    else if (detectItemVar.Equals("FIB") && r1.ReagentID2.Equals("咪唑缓冲液") && r1.loadDate2 > (int)Water / 66.7)
                    {
                        _hole = r1.holeNumber;
                        break;
                    }
                    else if (r1.ReagentID2.Equals("稀释液") && r1.loadDate2 > (int)Water / 66.7)
                    {  //此处的稀释液代表的是纯水
                        _hole = r1.holeNumber;
                        break;
                    }
                }
            }

            if (_hole == -1)
            {
                //弹出 没有相应试剂   添加提醒
                MessageBox.Show("试剂列表没有稀释液！！", "提醒：", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                // return;
            }
            if (_hole < 31)
            {   //制冷区
                //通过孔位号 计算 XY轴坐标
                x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;
                y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y - off_Y_SamplerToReagent;
                z_R = Z1ReagentMaxDownDistance;
            }
            else
            {   //常温区
                x_R = x_Axis_HotReagent + ((_hole - 1) % 2) * offHotReagent_x;
                y_R = y_Axis_HotReagent + ((_hole - 1) / 2) * offHotReagent_y - off_Y_SamplerToReagent;
                z_R = Z1HotReagentMaxDownDistance;
            }

            //此处臂运动去吸液体
            //  Move_X_YArmToTarget(x_Axis_Emergency, y_Axis_Emergency);//XY轴移动到紧急样本区
            XMotorStatus = 0;
            YMotorStatus = 0;
            Move_X_YArmToTarget(x_R, y_R);//XY轴移动到冷试剂区
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成


            Z1DownDistanceWithLiquid(z_R);

            //此处根据返回的状态 是否需要重新 下降 吸取液体
            Pump1Status = 0;
            Pump1ToBreathLiquid(_Amount);
            WaitStatus(Pump1ID, ref Pump1Status); //检查泵1结束 
            Z1MotorStatus = 0;
            Z1ReturnToZero();  //Z1轴回到零点
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            Can.SendCan(Z1MotorID, "1IQ" + "\r");

            Thread.Sleep(100);
        }
        /// <summary>
        /// 移动臂到样本区并吸取样本
        /// </summary>
        public static void MoveSampleNeedleToSampleOrWater(int count, int amout)
        {
            int _Amount = emptyAsrip + amout; //空吸+液量
            //int x_R = x_Axis_Sample + ((int)(ServiceProvider.SampleList[0].SampleInfoID - 1) % 15) * offSampleSet_x;
            //int  y_R = y_Axis_Sample + ((int)(ServiceProvider.SampleList[0].SampleInfoID - 1) / 15) * offSampleSet_y; 
            int z_R = Z1MaxDowndistance;
            int x_R = x_Axis_Sample + (count - 2) * offSampleSet_x;
            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_R, y_Axis_Sample);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            //此处吸3000空气
            //吸样本之前再吸空气
            Pump1Status = 0;
            Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
            WaitStatus(Pump1ID, ref Pump1Status); //检查泵1结束

            //Z1下移
            Z1DownDistanceWithLiquid(z_R);

            //此处根据返回的状态 是否需要重新 下降 吸取液体
            Pump1Status = 0;
            Pump1ToBreathLiquid(_Amount);
            WaitStatus(Pump1ID, ref Pump1Status); //检查泵2结束 
            Z1MotorStatus = 0;
            Z1ReturnToZero();  //Z1轴回到零点
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z2是否完成
            Can.SendCan(Z1MotorID, "1IQ" + "\r");
        }


        /// <summary>
        /// 添加样本
        /// </summary>
        public static void DilutionSample()
        {
            int z_R = Z1MaxDowndistance;

            Z1MotorStatus = 0;
            Z1DownDistanceAtDetectArea(z_R - 600);  //Z1下移一段距离
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束

            Pump1Status = 0;
            AddSampleToDetectUsePump1(); //泵释放样本
            WaitStatus(Pump1ID, ref Pump1Status); //检查是否结束

            Z1MotorStatus = 0;
            Z1ReturnToZero(); //Z1上移到顶点
            WaitStatus(Z1MotorID, ref Z1MotorStatus);  //检查Z1是否结束
            Can.SendCan(Z1MotorID, "1IQ" + "\r");
            //如有状态跟踪 置相应状态
        }


        /// <summary>
        /// 复位
        /// </summary>
        public static void ResetAllAxis()
        {
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            resetZ1_Axis(); //复位z1轴
            resetZ2_Axis();//复位Z2轴
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            //Z1MotorStatus = 0;
            //Z2MotorStatus = 0;
            //Z1DownALittle();//Z1下移一段距离
            //Z2DownALittle();//Z2下移一段距离
            //WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            //WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            //Z1MotorStatus = 0;
            //Z2MotorStatus = 0;
            //resetZ1_Axis(); //复位z1轴
            //resetZ2_Axis();//复位Z2轴
            //WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            //WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            //Can.SendCan(Z1MotorID, "1AC200" + "\r");
            //Can.SendCan(Z1MotorID, "1DE200" + "\r");
            //Can.SendCan(Z2MotorID, "2AC200" + "\r");
            //Can.SendCan(Z2MotorID, "2DE200" + "\r");

            XMotorStatus = 0;
            YMotorStatus = 0;
            resetX_Axis(); //复位X轴
            resetY_Axis(); //复位Y轴
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            Z1DownALittle();//Z1下移一段距离
            Z2DownALittle();//Z2下移一段距离
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            resetZ1_Axis(); //复位z1轴
            resetZ2_Axis();//复位Z2轴
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            Can.SendCan(Z1MotorID, "1AC200" + "\r");
            Can.SendCan(Z1MotorID, "1DE200" + "\r");
            Can.SendCan(Z2MotorID, "2AC200" + "\r");
            Can.SendCan(Z2MotorID, "2DE200" + "\r");
            Can.SendCan(Z1MotorID, "1CC3" + "\r");
            Can.SendCan(Z2MotorID, "2CC3" + "\r");

            XMotorStatus = 0;
            YMotorStatus = 0;
            X_FirstWalkALittle();//X轴出来一段
            Y_FirstWalkALittle();//Y轴出来一段
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            XMotorStatus = 0;
            YMotorStatus = 0;
            resetX_Axis(); //复位X轴
            resetY_Axis(); //复位Y轴
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            //my_can.SendCANData(83, "1IF" + "\r");
            Can.SendCan(XMotorID, "1IF" + "\r");
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            Can.SendCan(YMotorID, "1IF" + "\r");


            //初始化计时器  废液显示的图标
            rubbishWaterTimer = new System.Timers.Timer();
            rubbishWaterTimer.Elapsed += new System.Timers.ElapsedEventHandler((ss, ee) =>
            {
                if (through)
                {
                    through = false;
                    ServiceProvider.Monitor.DiscardSolutionState = ComponentStateEnum.ALERT;  //红色图标
                    RubbishBucketStatus = 0;
                    Can.SendCan(88, "1DS5" + "\r");
                }
                else
                {
                    through = true;
                    ServiceProvider.Monitor.DiscardSolutionState = ComponentStateEnum.ERROR;   //灰色图标
                }
                if (RubbishBucketStatus == 2)
                {
                    rubbishWaterTimer.Stop();
                    rubbishWaterTimer.Close();
                    ServiceProvider.Monitor.DiscardSolutionState = ComponentStateEnum.NORMAL;   //灰色图标
                }
            });
            rubbishWaterTimer.Interval = 1000;


            washWaterTimer = new System.Timers.Timer();
            washWaterTimer.Elapsed += new System.Timers.ElapsedEventHandler((ss, ee) =>
            {
                if (throughFlag)
                {
                    throughFlag = false;
                    ServiceProvider.Monitor.RinseFlaskState = ComponentStateEnum.ALERT;  //红色图标
                    BucketStatus = 0;
                    Can.SendCan(88, "1DS6" + "\r");
                }
                else
                {
                    throughFlag = true;
                    ServiceProvider.Monitor.RinseFlaskState = ComponentStateEnum.ERROR;   //灰色图标
                }
                if (BucketStatus == 1)
                {
                    washWaterTimer.Stop();
                    washWaterTimer.Close();
                    ServiceProvider.Monitor.RinseFlaskState = ComponentStateEnum.NORMAL;   //灰色图标
                }
            });
            washWaterTimer.Interval = 1000;
        }

        //初始化操作
        public static void Init(int clearDistance)
        {
            //--- 定位清洗位 ----
            XMotorStatus = 0;
            YMotorStatus = 0;
            Move_X_YArmToTarget(x_Axis_CleanArea, y_Axis_CleanArea);      //移动X轴到清洗位
                                                                          //移动Y轴到清洗位

            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

            //发送命令 检查是否液体已经满或者清洗液是否足
            SendBucketData();
            //CheckRubbishBucket();
            //CheckCleanBucket();

            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            Z1_Z2ClearAreaDownDistance(13000);//Z1 Z2下移一段距离    clearDistance

            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成            
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成

            Pump1Status = 0;
            Pump2Status = 0;
            ResetPump1(); //泵1开始复位
            ResetPump2();//泵2开始复位

            WaitStatus(Pump1ID, ref Pump1Status);//检查泵1结束
            Can.SendCan(Pump1ID, "1AC100" + "\r");
            Can.SendCan(Pump1ID, "1DE200" + "\r");
            WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

            Can.SendCan(Pump2ID, "2AC200" + "\r");   //由100改成了200 礼拜日4.8
            Can.SendCan(Pump2ID, "2DE200" + "\r");

            ClearNeedles(InitCleanTime); //开启清洗 并定时到时间关闭

            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            Z1ReturnToZeroInit(); //Z1上移到原点
            Z2ReturnToZeroInit(); //Z2上移到原点
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成

            Can.SendCan(Z1MotorID, "1IQ" + "\r");
            Can.SendCan(Z2MotorID, "2IQ" + "\r");


            Pump1Status = 0;
            Pump2Status = 0;
            //  Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
            Pump2ToBreatheAir(emptyAsrip);//泵2吸3000空气
                                          //  WaitStatus(Pump1ID, ref Pump1Status);//检查泵1结束
            WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束


            //检查是否已满或者清洗液不够
            CheckRubbishBucket();





        }
        public static void ClearNeedles(int clearTime)
        {
            //开启清洗 并定时  到时间关闭
            //8号开
            Can.SendCan(Pump1ID, "1OH8" + "\r");
            Can.SendCan(Pump1ID, "1OH9" + "\r");
            Can.SendCan(Pump1ID, "1OH5" + "\r");
            Can.SendCan(Pump1ID, "1OH4" + "\r");
            Can.SendCan(Pump1ID, "1OH0" + "\r");
            Can.SendCan(Pump1ID, "1OH2" + "\r");
            //my_can.SendCANData(88, "1OH7" + "\r");

            Thread.Sleep(clearTime);

            Can.SendCan(Pump1ID, "1OL0" + "\r");
            Can.SendCan(Pump1ID, "1OL2" + "\r");
            Can.SendCan(Pump1ID, "1OL5" + "\r");
            Can.SendCan(Pump1ID, "1OL4" + "\r");
            Can.SendCan(Pump1ID, "1OL8" + "\r");
            Can.SendCan(Pump1ID, "1OL9" + "\r");
        }

        //static int dispCount = 0;
        /// <summary>
        /// 试剂针吸样操作， 包括试剂2 试剂3的吸取 判别方式由杯子的状态 确定
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <param name=""></param>
        public static void AsprieReagent()
        {
            // dispCount++;
            //if (dispCount % 2 == 0)
            //{
            //    MoveArmToClearArea(0, 3000);
            //}

            int liquidChange = 0;

            int _Amount = 0;
            int _hole = 0;

            int x_R = 0;

            int y_R = 0;

            int z_R = 0;
            //查看对应杯的状态 确认需要吸取那种试剂 如为SAMPLE 吸取试剂2
            if (ServiceProvider.CupStrip[ServiceProvider.ReagentList[0].StripID].Cups[ServiceProvider.ReagentList[0].CupSeatID].getStatus() == Cup.CupHoleStatusEnum.SAMPLE)
            {
                //获取试剂2  相关参数
                _Amount = (int)(emptyAsrip + ServiceProvider.ReagentList[0].DetectItemModel.reagentAmount2 * ReagntFor1UL);
                //获取试剂 孔位号， 通过检测项 检索出可 用试剂位；
                //偏历相应孔位
                foreach (Clipper.Model.ReagentKit r2 in ServiceProvider.ReagentKitVM.ReagentKitList)
                {
                    if (r2.ReagentID2 != null)
                    {
                        if (r2.ReagentID2.Equals(ServiceProvider.ReagentList[0].DetectItemModel.reagentName2) && r2.loadDate2 > ServiceProvider.ReagentList[0].DetectItemModel.reagentAmount2)
                        {
                            _hole = r2.holeNumber;
                            break;
                        }
                    }
                }
                liquidChange = ServiceProvider.ReagentList[0].DetectItemModel.reagentAmount2;  //相应的减去的量
            }
            else if (ServiceProvider.CupStrip[ServiceProvider.ReagentList[0].StripID].Cups[ServiceProvider.ReagentList[0].CupSeatID].getStatus() == Cup.CupHoleStatusEnum.REAGENT1)//定位试剂3 并吸取
            {
                //获取试剂2  相关参数
                _Amount = (int)(emptyAsrip + ServiceProvider.ReagentList[0].DetectItemModel.reagentAmount3 * ReagntFor1UL);
                //获取试剂 孔位号， 通过检测项 检索出可 用试剂位；
                //偏历相应孔位
                foreach (Clipper.Model.ReagentKit r3 in ServiceProvider.ReagentKitVM.ReagentKitList)
                {
                    if (r3.ReagentID2 != null)
                    {
                        if (r3.ReagentID2.Equals(ServiceProvider.ReagentList[0].DetectItemModel.reagentName3) && r3.loadDate2 > ServiceProvider.ReagentList[0].DetectItemModel.reagentAmount3)
                        {
                            _hole = r3.holeNumber;
                            break;
                        }
                    }
                }
                liquidChange = ServiceProvider.ReagentList[0].DetectItemModel.reagentAmount3;  //相应的减去的量


            }
            if (_hole == 0)
            {
                //弹出 没有相应试剂
                return;
            }
            if (_hole < 31)
            {   //制冷区
                //通过孔位号 计算 XY轴坐标
                x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;

                y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y;

                z_R = Z2ReagentMaxDownDistance;
            }
            else
            {   //常温区
                x_R = x_Axis_HotReagent + ((_hole - 31) % 2) * offHotReagent_x;

                y_R = y_Axis_HotReagent + ((_hole - 31) / 2) * offHotReagent_y;

                z_R = Z2HotReagentMaxDownDistance;
            }

            if (!lastReagentName.Equals(ServiceProvider.ReagentList[0].DetectItemModel.reagentName3))
            {
                IsReagentAsripe = true;
            }
            lastReagentName = ServiceProvider.ReagentList[0].DetectItemModel.reagentName3;


            if (true)
            {
                XMotorStatus = 0;
                YMotorStatus = 0;
                //Pump2Status = 0;//==========
                ////此处臂运动去吸液体
                //Pump2ToBreatheAir(emptyAsrip +1000);//泵2再吸3000空气=======
                Move_X_YArmToTarget(x_R, y_R);//XY轴移动
                                              // WaitStatus(Pump2ID, ref Pump2Status);   //检查泵2结束 是否可以空吸
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

                Pump2Status = 0;
                Pump2ToBreatheAir(emptyAsrip);//泵2吸3000空气
                WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束
                                                      // _Amount += 1000;//============
                Z2DownDistanceWithLiquid(z_R);

                //此处根据返回的状态 是否需要重新 下降 吸取液体
                Pump2Status = 0;
                Pump2ToBreathLiquid(_Amount);
                WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束 

                ServiceProvider.VariableClass.Z2Amount = _Amount;   //给Z2所有值

                //根据孔位号进行减少量
                ServiceProvider.ReagentKitVM.ReagentKitList[_hole - 1].ReagentModel1.ReagentLeft = ServiceProvider.ReagentKitVM.ReagentKitList[_hole - 1].ReagentModel1.ReagentLeft - (int)((_Amount - emptyAsrip) / ReagntFor1UL);


                Z2MotorStatus = 0;
                Z2ReturnToZero();  //Z2轴回到零点
                WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
                Can.SendCan(Z2MotorID, "2IQ" + "\r");
                Pump2ToBreathLiquid(_Amount + 1000); //再次吸  为了防止有试剂挤出   之前为1500

            }
            //如有状态跟踪 置相应状态 


            #region  // 即使更新试剂剩余的量  试剂的减去的量 
            if (_hole > 0)
            {
                //Clipper.Model.ReagentKit reagentKit = mReagentKitDal.GetModel(_hole);
                //reagentKit.loadDate2 = (int)reagentKit.loadDate2 - liquidChange;
                //mReagentKitDal.UpdateReagentQuantity(reagentKit);
                //ServiceProvider.ReagentKitVM.ReagentKitList = mReagentKitDal.GetModelListReagentKit();
            }
            #endregion

        }
        /// <summary>
        /// 试剂针加样操作， 包括试剂2 试剂3的添加 判别方式由杯子的状态 确定
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <param name=""></param>
        public static void DispendReagent()
        {

            int z_R = Z2DetectMaxDownDistance;

            int x_R = x_Axis_Detect + ServiceProvider.ReagentList[0].CupSeatID * offDetectSet_x;
            int y_R = y_Axis_Detect + ServiceProvider.ReagentList[0].StripID * offDetectSet_y + off_Y_SamplerToReagent;


            if (true)
            {
                //此处臂运动去添加液体
                XMotorStatus = 0;
                YMotorStatus = 0;
                Move_X_YArmToTarget(x_R, y_R);  //X轴定位到检测区  坐标Y轴少走50步

                //Y轴定位到检测区
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成


                //if (ServiceProvider.ReagentList[0].DetectItem.Equals("DD") || ServiceProvider.ReagentList[0].DetectItem.Equals("PT"))
                //{
                //    //   AddReagentToDetectUsePump2DD(5000); //泵释放试剂
                //}
                //else
                //{
                Z2MotorStatus = 0;
                Z2DownDistanceAtDetectArea(z_R - 3000); //Z2下移一段距离
                WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                Pump2Status = 0;
                AddReagentToDetectUsePump2(); //泵释放试剂
                WaitStatus(Pump2ID, ref Pump2Status);  //检查泵是否结束
                                                       //}

                // Thread.Sleep(2000);


                ServiceProvider.ReagentList[0].RecordTime = DateTime.Now;

                //===========================添加吸打混匀操作=============
                //if (ServiceProvider.ReagentList[0].DetectItem.Equals("APTT") ||
                //    ServiceProvider.ReagentList[0].DetectItem.Equals("PT"))
                //{
                //    //for (int pp = 0; pp < 1; pp++)
                //    //{
                //    //    //Pump2Status = 0; 
                //    //Pump2ToBreathLiquid(6000);           //xi
                //    //WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

                //    Z2MotorStatus = 0;
                //    if (ServiceProvider.ReagentList[0].StripID == 0)
                //    {
                //        Z2DownDistanceAtDetectArea(z_R - detect1Variable); //Z2下移一段距离  改动前670  650
                //    }
                //    else if (ServiceProvider.ReagentList[0].StripID == 3)
                //    {
                //        Z2DownDistanceAtDetectArea(z_R - detect4Variable); //Z2下移一段距离 检测位4的下移距离 改动前860   890
                //    }
                //    else
                //    {
                //        Z2DownDistanceAtDetectArea(z_R - detect23Variable);   //Z2下移一段距离   检测位 23 的减去的距离 790
                //    }

                //    WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                //    Pump2Status = 0;
                //    Pump2ToBreathLiquid(9000);           //xi
                //    WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

                //    Z2MotorStatus = 0;
                //    Z2DownDistanceAtDetectArea(z_R - 3000); //Z2定位点 -2400
                //    WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                //    Pump2Status = 0;
                //    AddReagentToDetectUsePump2(); //泵释放试剂   da
                //    WaitStatus(Pump2ID, ref Pump2Status);  //检查泵是否结束
                //    //}
                //    //Z2MotorStatus = 0;
                //    //Z2DownDistanceAtDetectArea(z_R - 2000); //
                //    //WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                //    Z2MotorStatus = 0;  //此处控制打完试剂针头不粘连反应物
                //    Z2DownDistanceAtDetectArea(z_R - 850); //-850
                //    WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束
                //}

                if (ServiceProvider.ReagentList[0].DetectItem.Equals("DD") || ServiceProvider.ReagentList[0].DetectItem.Equals("DDTEST"))
                {
                    gunOnce(z_R, 2);
                    #region 简化详情
                    //for (int pp = 0; pp < 2; pp++)
                    //{
                    //    //Pump2Status = 0; 
                    //    //Pump2ToBreathLiquid(6000);           //xi
                    //    //WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

                    //    Z2MotorStatus = 0;
                    //    if (ServiceProvider.ReagentList[0].StripID == 0)
                    //    {
                    //        Z2DownDistanceAtDetectArea(z_R - detect1Variable); //Z2下移一段距离  改动前670  650
                    //    }
                    //    else if (ServiceProvider.ReagentList[0].StripID == 3)
                    //    {
                    //        Z2DownDistanceAtDetectArea(z_R - detect4Variable); //Z2下移一段距离 检测位4的下移距离 改动前860   890
                    //    }
                    //    else
                    //    {
                    //        Z2DownDistanceAtDetectArea(z_R - detect23Variable);   //Z2下移一段距离   检测位 23 的减去的距离 790
                    //    }
                    //    WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                    //    //Pump2Status = 0;
                    //    //AddReagentToDetectUsePump2DD(2000); //泵释放试剂
                    //    //WaitStatus(Pump2ID, ref Pump2Status);  //检查泵是否结束


                    //    Pump2Status = 0;
                    //    Pump2ToBreathLiquid(9000);           //xi
                    //    WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束


                    //    Z2MotorStatus = 0;                                        //-------
                    //    Z2DownDistanceAtDetectArea(z_R - 3500); //Z2定位点 -2400
                    //    WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束//--------

                    //    Pump2Status = 0;
                    //    AddReagentToDetectUsePump2DD(3000); //泵释放试剂   da
                    //    WaitStatus(Pump2ID, ref Pump2Status);  //检查泵是否结束
                    //}
                    ////Z2MotorStatus = 0;
                    ////Z2DownDistanceAtDetectArea(z_R - 2000); //
                    ////WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                    //Z2MotorStatus = 0;  //此处控制打完试剂针头不粘连反应物//-----------------------
                    //Z2DownDistanceAtDetectArea(z_R - 850); //-850
                    //WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束//--------------
                    #endregion
                }
                else
                {
                    gunOnce(z_R, 1);
                }
                //=======================================================
                //Z2MotorStatus = 0;
                //Z2DownDistanceAtDetectArea(z_R - 1800); //Z2下移一段距离
                //WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                Z2MotorStatus = 0;
                Z2ReturnToZero(); //Z2上移到顶点
                WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
                Can.SendCan(Z2MotorID, "2IQ" + "\r");
            }
            ////如有状态跟踪 置相应状态
            //MoveArmToClearAreaSample(0, 1500);
            ////去吸清洗液B
            //CleanNeedleReagent2(ServiceProvider.VariableClass.Z2Amount);
        }

        public static void gunOnce(int z_R, int time)
        {
            for (int pp = 0; pp < time; pp++)
            {
                //Pump2Status = 0; 
                //Pump2ToBreathLiquid(6000);           //xi
                //WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

                Z2MotorStatus = 0;
                if (ServiceProvider.ReagentList[0].StripID == 0)
                {
                    Z2DownDistanceAtDetectArea(z_R - detect1Variable); //Z2下移一段距离  改动前670  650
                }
                else if (ServiceProvider.ReagentList[0].StripID == 3)
                {
                    Z2DownDistanceAtDetectArea(z_R - detect4Variable); //Z2下移一段距离 检测位4的下移距离 改动前860   890
                }
                else
                {
                    Z2DownDistanceAtDetectArea(z_R - detect23Variable);   //Z2下移一段距离   检测位 23 的减去的距离 790
                }
                WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

                //Pump2Status = 0;
                //AddReagentToDetectUsePump2DD(2000); //泵释放试剂
                //WaitStatus(Pump2ID, ref Pump2Status);  //检查泵是否结束


                Pump2Status = 0;
                Pump2ToBreathLiquid(9000);           //xi
                WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束


                Z2MotorStatus = 0;                                        //-------
                Z2DownDistanceAtDetectArea(z_R - 3500); //Z2定位点 -2400
                WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束//--------

                Pump2Status = 0;
                AddReagentToDetectUsePump2DD(3000); //泵释放试剂   da
                WaitStatus(Pump2ID, ref Pump2Status);  //检查泵是否结束
            }
            //Z2MotorStatus = 0;
            //Z2DownDistanceAtDetectArea(z_R - 2000); //
            //WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束

            Z2MotorStatus = 0;  //此处控制打完试剂针头不粘连反应物//-----------------------
            Z2DownDistanceAtDetectArea(z_R - 850); //-850
            WaitStatus(Z2MotorID, ref Z2MotorStatus);  //检查Z2是否结束//--------------
        }

        /// <summary>
        /// 样本针吸样操作，包括是否吸取试剂1
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <param name=""></param>
        public static void AsprieSample()
        {
            int _Amount = 0;
            int _hole = -1;
            int x_R = 0;

            int y_R = 0;

            int z_R = 0;
            bool isGo = true;

            if (ServiceProvider.SampleList[0].DetectItemModel.reagentAmount1 != 0)
            {
                isGo = false;
                //先吸试剂1
                //获取试剂1  相关参数
                _Amount = (int)(emptyAsrip + ServiceProvider.SampleList[0].DetectItemModel.reagentAmount1 * SampleFor1UL);
                //获取试剂 孔位号， 通过检测项 检索出可 用试剂位；
                //偏历相应孔位
                foreach (Clipper.Model.ReagentKit r1 in ServiceProvider.ReagentKitVM.ReagentKitList)
                {
                    if (r1.ReagentID2 != null)
                    {
                        if (r1.ReagentID2.Equals(ServiceProvider.SampleList[0].DetectItemModel.reagentName1) && r1.loadDate2 > ServiceProvider.SampleList[0].DetectItemModel.reagentAmount1)
                        {
                            lastSampleName = ServiceProvider.SampleList[0].DetectItemModel.reagentName1;  //把样本名字给样本
                            _hole = r1.holeNumber;
                            break;
                        }
                    }
                }
                if (_hole == -1)
                {
                    //弹出 没有相应试剂
                    return;
                }
                if (_hole < 31)
                {   //制冷区
                    //通过孔位号 计算 XY轴坐标
                    x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;


                    y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y - off_Y_SamplerToReagent;

                    z_R = Z1ReagentMaxDownDistance;
                }
                else
                {   //常温区
                    x_R = x_Axis_HotReagent + ((_hole - 1) % 6) * offHotReagent_x;


                    y_R = y_Axis_HotReagent + ((_hole - 1) / 6) * offHotReagent_y - off_Y_SamplerToReagent;

                    z_R = Z1HotReagentMaxDownDistance;
                }


                if (true)
                {
                    XMotorStatus = 0;
                    YMotorStatus = 0;

                    //此处臂运动去吸液体
                    Move_X_YArmToTarget(x_R, y_R);//XY轴移动

                    WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                    WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
                    //吸样本之前再吸空气
                    Pump1Status = 0;
                    Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
                    WaitStatus(Pump1ID, ref Pump1Status); //检查泵1结束


                    Z1DownDistanceWithLiquid(z_R);

                    //此处根据返回的状态 是否需要重新 下降 吸取液体
                    Pump1Status = 0;
                    Pump1ToBreathLiquid(_Amount);
                    WaitStatus(Pump1ID, ref Pump1Status); //检查泵2结束 
                    Z1MotorStatus = 0;
                    Z1ReturnToZero();  //Z2轴回到零点
                    WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z2是否完成
                    Can.SendCan(Z1MotorID, "1IQ" + "\r");
                }
            }
            //吸样本 应当还有个 急诊位 的判别

            if (_Amount > 0)
            {
                _Amount += (int)(ServiceProvider.SampleList[0].DetectItemModel.bloodAmount * SampleFor1UL);
            }
            else
            {
                _Amount = (int)(emptyAsrip + ServiceProvider.SampleList[0].DetectItemModel.bloodAmount * SampleFor1UL);
            }
            x_R = x_Axis_Sample + ((int)(ServiceProvider.SampleList[0].SampleInfoID - 1) % 15) * offSampleSet_x;
            y_R = y_Axis_Sample + ((int)(ServiceProvider.SampleList[0].SampleInfoID - 1) / 15) * offSampleSet_y;
            z_R = Z1MaxDowndistance;


            if (!ServiceProvider.SampleList[0].DetectItemModel.reagentName2.Equals(lastSampleName))
            {
                IsSampleAsripe = true;
            }
            lastSampleName = ServiceProvider.SampleList[0].DetectItemModel.reagentName2; //结果赋值

            if (true)
            {
                XMotorStatus = 0;
                YMotorStatus = 0;
                Move_X_YArmToTarget(x_R, y_R); //移动x轴到样本区
                //移动Y轴到样本区
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

                if (isGo)
                {
                    Pump1Status = 0;
                    Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
                    WaitStatus(Pump1ID, ref Pump1Status); //检查泵1结束
                }

                Z1DownDistanceWithLiquid(z_R);

                Pump1Status = 0;
                Pump1ToBreathLiquid(_Amount); //开启开关去吸试剂
                WaitStatus(Pump1ID, ref Pump1Status); //检查结束

                ServiceProvider.VariableClass.Z1Amount = _Amount;//给Z1一个全局的值

                Z1MotorStatus = 0;
                Z1ReturnToZero();//Z1轴回到零点
                WaitStatus(Z1MotorID, ref Z1MotorStatus);//检查结束  
                Can.SendCan(Z1MotorID, "1IQ" + "\r");
            }

        }
        /// <summary>
        /// 样本针加样操作1
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <param name=""></param>
        public static void DispendSample()
        {
            int z_R = Z1DetectMaxDownDistance;

            int x_R = x_Axis_Detect + ServiceProvider.SampleList[0].CupSeatID * offDetectSet_x;
            int y_R = y_Axis_Detect + ServiceProvider.SampleList[0].StripID * offDetectSet_y;


            if (true)
            {
                //此处臂运动去添加液体
                XMotorStatus = 0;
                YMotorStatus = 0;
                Move_X_YArmToTarget(x_R, y_R); //移动x轴到检测区
                //移动Y轴到检测区
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

                Z1MotorStatus = 0;
                Z1DownDistanceAtDetectArea(z_R - 300);  //Z1下移一段距离
                WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束

                Pump1Status = 0;
                AddSampleToDetectUsePump1(); //泵释放样本
                WaitStatus(Pump1ID, ref Pump1Status); //检查是否结束

                //Z1MotorStatus = 0;
                //Z1DownDistanceAtDetectArea(z_R - 300);  //Z1下移一段距离
                //WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束

                Z1MotorStatus = 0;
                Z1ReturnToZero(); //Z1上移到顶点
                WaitStatus(Z1MotorID, ref Z1MotorStatus);  //检查Z1是否结束
                Can.SendCan(Z1MotorID, "1IQ" + "\r");
                //如有状态跟踪 置相应状态
            }
            //MoveArmToClearAreaSample(0, 1500);
            ////去吸清洗液B
            // CleanNeedle(ServiceProvider.VariableClass.Z1Amount);
        }
        public static void MoveArmToRegentOrSample()
        {

            //读取试剂列表 
            //读取样本列表
            bool clean = false;
            bool regentGo = false;
            //    emptyAsrip = 3000;
            if (ServiceProvider.ReagentList.Count > 0)  //判断是否样本列表和试剂列表有值
            {
                Console.WriteLine("开始吸取试剂");
                AsprieReagent(); //吸取试剂
                regentGo = true;
            }

            if (ServiceProvider.SampleList.Count > 0)
            {
                clean = true;
                Console.WriteLine("吸取样本并添加");
                //表示开始添加样本
                ServiceProvider.CupStrip[ServiceProvider.SampleList[0].StripID].Cups[ServiceProvider.SampleList[0].CupSeatID].setStatus(Clipper.Model.DetectionModel.Cup.CupHoleStatusEnum.SAMPLEStart);

                AsprieSample();
                DispendSample();
                waitStatus = true; //开启等待模式
                //表示添加完样本
                ServiceProvider.CupStrip[ServiceProvider.SampleList[0].StripID].Cups[ServiceProvider.SampleList[0].CupSeatID].setStatus(Clipper.Model.DetectionModel.Cup.CupHoleStatusEnum.SAMPLE);
                ServiceProvider.SampleList.RemoveAt(0);
            }
            if (ServiceProvider.ReagentList.Count > 0 && regentGo)   //判断是否样本列表和试剂列表有值
            {
                clean = true;
                Console.WriteLine("添加试剂");
                DispendReagent(); //添加试剂
                cleanReagent = true; //进入Z2进行

                if (ServiceProvider.CupStrip[ServiceProvider.ReagentList[0].StripID].Cups[ServiceProvider.ReagentList[0].CupSeatID].getStatus() == Clipper.Model.DetectionModel.Cup.CupHoleStatusEnum.SAMPLE)
                    ServiceProvider.CupStrip[ServiceProvider.ReagentList[0].StripID].Cups[ServiceProvider.ReagentList[0].CupSeatID].setStatus(Clipper.Model.DetectionModel.Cup.CupHoleStatusEnum.REAGENT1);
                else
                    ServiceProvider.CupStrip[ServiceProvider.ReagentList[0].StripID].Cups[ServiceProvider.ReagentList[0].CupSeatID].setStatus(Clipper.Model.DetectionModel.Cup.CupHoleStatusEnum.REAGENT2);
                ServiceProvider.ReagentList.RemoveAt(0);
            }

            if (clean)
            {

                MoveArmToClearArea(0, 2200, true);
            }
            while (IsPause)
            {
                Thread.Sleep(100);
            }
        }
        static bool waitStatus = false;
        static bool cleanReagent = false;

        //移动臂到清洗区
        public static void MoveArmToClearArea(int clearDistance0, int clearTime, bool isAsprie)
        {
            if (ServiceProvider.Monitor.MdcConfiger.isClearNeeedle)
            {
                //    MoveArmToClearAreaSample(0, 1500);
                if (waitStatus)
                {
                    waitStatus = false;
                    //if (IsSampleAsripe)
                    //{
                    //去吸清洗液B
                    CleanNeedle(100 * 67 + 3000);
                    //}
                }
                if (cleanReagent)
                {
                    cleanReagent = false;
                    //if (IsReagentAsripe)
                    //{
                    //如有状态跟踪 置相应状态
                    // MoveArmToClearAreaSample(0, 1500);ServiceProvider.VariableClass.Z2Amount
                    //去吸清洗液B
                    CleanNeedleReagent2(100 * 67 + 3000);
                    //}
                }
            }

            Console.WriteLine("清洗");
            XMotorStatus = 0;
            YMotorStatus = 0;
            if (true)
            {
                Move_X_YArmToTarget(x_Axis_CleanArea, y_Axis_CleanArea);  //X轴定位到清洗区
                //Y轴定位到清洗区
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

                //静置一秒中
                //if (waitStatus)
                //{
                // Thread.Sleep(1000);
                // waitStatus = false;
                //}

                //发送命令 检查是否液体已经满或者清洗液是否足够
                SendBucketData();

                Z1MotorStatus = 0;
                Z2MotorStatus = 0;
                Z1_Z2ClearAreaDownDistance(clearDistance); //Z2和Z1下移一段距离

                WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束
                WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
                Pump1Status = 0;
                Pump2Status = 0;
                ResetPump1(); //泵1开始复位
                ResetPump2();//泵2开始复位
                ClearNeedles(clearTime);  //开启阀门进行冲洗试剂和样本针
                WaitStatus(Pump1ID, ref Pump1Status);//检查泵1结束
                WaitStatus(Pump2ID, ref Pump2Status);//检查泵2结束

                Pump1Status = 0;
                Pump2Status = 0;
                Z1MotorStatus = 0;
                Z2MotorStatus = 0;
                Z1ReturnToZero(); //Z1上移到顶点

                Z2ReturnToZero(); //Z2上移到顶点
                //Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
                //Pump2ToBreatheAir(emptyAsrip);//泵2吸3000空气

                WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束
                WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
                Can.SendCan(Z1MotorID, "1IQ" + "\r");
                Can.SendCan(Z2MotorID, "2IQ" + "\r");

                //WaitStatus(Pump1ID, ref Pump1Status); //检查泵1结束
                //WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

                //检查是否已满或者清洗液不够
                CheckRubbishBucket();

            }
        }

        public static void MoveArmToClearAreaSample(int clearDistance0, int clearTime)
        {
            Console.WriteLine("清洗");
            XMotorStatus = 0;
            YMotorStatus = 0;
            if (true)
            {
                Move_X_YArmToTarget(x_Axis_CleanArea, y_Axis_CleanArea);  //X轴定位到清洗区
                //Y轴定位到清洗区
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

                //发送命令 检查是否液体已经满或者清洗液是否足够
                SendBucketData();

                Z1MotorStatus = 0;
                Z2MotorStatus = 0;
                Z1_Z2ClearAreaDownDistance(clearDistance); //Z2和Z1下移一段距离

                WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束
                WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
                Pump1Status = 0;
                Pump2Status = 0;
                ResetPump1(); //泵1开始复位
                ResetPump2();//泵2开始复位
                ClearNeedles(clearTime);  //开启阀门进行冲洗试剂和样本针
                WaitStatus(Pump1ID, ref Pump1Status);//检查泵1结束
                WaitStatus(Pump2ID, ref Pump2Status);//检查泵2结束

                Pump1Status = 0;
                Pump2Status = 0;
                Z1MotorStatus = 0;
                Z2MotorStatus = 0;
                Z1ReturnToZero(); //Z1上移到顶点

                Z2ReturnToZero(); //Z2上移到顶点
                Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
                Pump2ToBreatheAir(emptyAsrip);//泵2吸3000空气

                WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束
                WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
                Can.SendCan(Z1MotorID, "1IQ" + "\r");
                Can.SendCan(Z2MotorID, "2IQ" + "\r");

                WaitStatus(Pump1ID, ref Pump1Status); //检查泵1结束
                WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束

                //检查是否已满或者清洗液不够
                CheckRubbishBucket();

            }
        }


        /// <summary>
        /// 发送命令判断水桶的状态
        /// </summary>
        public static void SendBucketData()
        {
            RubbishBucketStatus = 0;
            Can.SendCan(88, "1DS5" + "\r");

            BucketStatus = 0;
            Can.SendCan(88, "1DS6" + "\r");
        }

        /// <summary>
        /// 检测水桶的反应(废液桶)
        /// </summary>
        public static void CheckRubbishBucket()
        {
            if (RubbishBucketStatus == 1)
            {
                rubbishWaterTimer.Start();  //开启废液闪烁计时器
                MessageBox.Show("废水已满,请您清理！！", "警告:", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);

            }
            if (BucketStatus == 2)
            {
                washWaterTimer.Start();
                MessageBox.Show("清洗液已经不足,请您添加！", "警告:", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);

            }

        }
        public static void SendWaterFullCommand()
        {
            RubbishBucketStatus = 0;
            Can.SendCan(88, "1DS5" + "\r");
        }

        public static void SendBucketCommand()
        {
            BucketStatus = 0;
            Can.SendCan(88, "1DS6" + "\r");
        }

        public static void ResetPump1()
        {
            Console.WriteLine("泵——1复位");
            Can.SendCan(Pump1ID, "1AC25" + "\r");
            Can.SendCan(Pump1ID, "1DE25" + "\r");
            Can.SendCan(Pump1ID, "1VE3" + "\r");
            Can.SendCan(Pump1ID, "1DI-1" + "\r");
            Can.SendCan(Pump1ID, "1SH1L" + "\r");


        }
        public static void ResetPump2()
        {
            Console.WriteLine("泵——2复位");
            Can.SendCan(Pump2ID, "2AC25" + "\r");
            Can.SendCan(Pump2ID, "2DE25" + "\r");
            Can.SendCan(Pump2ID, "2VE3" + "\r");
            Can.SendCan(Pump2ID, "2DI-1" + "\r");
            Can.SendCan(Pump2ID, "2SH2L" + "\r");
        }

        public static void Pump1ToBreathLiquid(int SampleLiquidQuantity)
        {
            Can.SendCan(Pump1ID, "1VE3" + "\r");
            Can.SendCan(Pump1ID, "1DI" + SampleLiquidQuantity + "\r");
            Can.SendCan(Pump1ID, "1FP" + "\r");
        }
        public static void Pump2ToBreathLiquid(int RegentLiquidQuantity)
        {
            Can.SendCan(Pump2ID, "2VE3" + "\r");
            Can.SendCan(Pump2ID, "2DI" + RegentLiquidQuantity + "\r");
            Can.SendCan(Pump2ID, "2FP" + "\r");
        }




        public static void Pump1ToBreatheAir(int breatheAir)
        {
            Can.SendCan(Pump1ID, "1VE5" + "\r");
            Can.SendCan(Pump1ID, "1DI" + breatheAir + "\r");
            Can.SendCan(Pump1ID, "1FP" + "\r");
        }

        public static void Pump2ToBreatheAir(int breatheAir)
        {
            Can.SendCan(Pump2ID, "2VE5" + "\r");
            Can.SendCan(Pump2ID, "2DI" + breatheAir + "\r");
            Can.SendCan(Pump2ID, "2FP" + "\r");
        }

        public static void AddSampleToDetectUsePump1()
        {
            Can.SendCan(Pump1ID, "1AC200" + "\r");   //由100改成了200 礼拜日4.8
            Can.SendCan(Pump1ID, "1DE200" + "\r");

            Can.SendCan(Pump1ID, "1VE9.5" + "\r");
            Can.SendCan(Pump1ID, "1DI3000" + "\r");
            Can.SendCan(Pump1ID, "1FP" + "\r");
        }

        public static void AddReagentToDetectUsePump2()
        {
            Can.SendCan(Pump2ID, "2AC200" + "\r");   //由100改成了200 礼拜日4.8
            Can.SendCan(Pump2ID, "2DE200" + "\r");

            Can.SendCan(Pump2ID, "2VE9.5" + "\r");// 更改前为 
            Can.SendCan(Pump2ID, "2DI3000" + "\r");
            Can.SendCan(Pump2ID, "2FP" + "\r");
        }

        public static void AddReagentToDetectUsePump2DD(int disp)
        {
            Can.SendCan(Pump2ID, "2AC200" + "\r");   //由100改成了200 礼拜日4.8
            Can.SendCan(Pump2ID, "2DE200" + "\r");

            Can.SendCan(Pump2ID, "2VE9.5" + "\r");// 更改前为 
            Can.SendCan(Pump2ID, "2DI" + disp + "\r");
            Can.SendCan(Pump2ID, "2FP" + "\r");
        }


        //在加液前先吐空气
        public static void PushAirToDetectUsePump2()
        {
            Can.SendCan(Pump2ID, "2VE5" + "\r");// 更改前为 
            Can.SendCan(Pump2ID, "2DI1500" + "\r");
            Can.SendCan(Pump2ID, "2FP" + "\r");
        }

        /// <summary>
        /// 复位吸针
        /// </summary>
        public static void resetZ1_Axis()
        {
            Console.WriteLine("Z1轴复位");

            Can.SendCan(Z1MotorID, "1AC25" + "\r");
            Can.SendCan(Z1MotorID, "1DE25" + "\r");
            Can.SendCan(Z1MotorID, "1VE1" + "\r");
            Can.SendCan(Z1MotorID, "1DI10" + "\r");
            Can.SendCan(Z1MotorID, "1SH1H" + "\r");

        }

        /// <summary>
        /// Z1返回到零点
        /// </summary>
        public static void Z1ReturnToZero()
        {
            Can.SendCan(Z1MotorID, "1VE9.5" + "\r");
            Can.SendCan(Z1MotorID, "1DI1" + "\r");
            Can.SendCan(Z1MotorID, "1FS1H" + "\r");

            //Can.SendCan(Z1MotorID, "1AC100" + "\r");
            //Can.SendCan(Z1MotorID, "1DE200" + "\r");     

        }
        public static void Z1ReturnToZeroInit()
        {
            Can.SendCan(Z1MotorID, "1VE5" + "\r");
            Can.SendCan(Z1MotorID, "1DI1" + "\r");
            Can.SendCan(Z1MotorID, "1FS1H" + "\r");

        }


        public static void Z2ReturnToZero()
        {
            Can.SendCan(Z2MotorID, "2VE9.5" + "\r");
            Can.SendCan(Z2MotorID, "2DI1" + "\r");
            Can.SendCan(Z2MotorID, "2FS2H" + "\r");

            //Can.SendCan(Z2MotorID, "2AC100" + "\r");
            //Can.SendCan(Z2MotorID, "2DE200" + "\r");

        }

        public static void Z2ReturnToZeroInit()
        {
            Can.SendCan(Z2MotorID, "2VE5" + "\r");
            Can.SendCan(Z2MotorID, "2DI1" + "\r");
            Can.SendCan(Z2MotorID, "2FS2H" + "\r");

        }

        public static void Z1DownALittle()
        {
            //my_can.SendCANData(65, "1VE3" + "\r");
            //my_can.SendCANData(65, "1DI-2000" + "\r");
            //my_can.SendCANData(65, "1FP" + "\r");

            Can.SendCan(Z1MotorID, "1VE3" + "\r");
            Can.SendCan(Z1MotorID, "1DI-2000" + "\r");
            Can.SendCan(Z1MotorID, "1FP" + "\r");
        }

        public static void Z1DownDistance(int z1distance)
        {
            //my_can.SendCANData(65, "1VE3" + "\r");
            //my_can.SendCANData(65, "1DI-2000" + "\r");
            //my_can.SendCANData(65, "1FP" + "\r");

            Can.SendCan(Z1MotorID, "1DE500" + "\r");
            Can.SendCan(Z1MotorID, "1VE9.5" + "\r");
            Can.SendCan(Z1MotorID, "1DI-" + z1distance + "\r");
            Can.SendCan(Z1MotorID, "1FP" + "\r");
            // WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
        }

        public static void Z1DownDistance2(int z1distance)
        {
            //my_can.SendCANData(65, "1VE3" + "\r");
            //my_can.SendCANData(65, "1DI-2000" + "\r");
            //my_can.SendCANData(65, "1FP" + "\r");

            Can.SendCan(Z1MotorID, "1DE500" + "\r");
            Can.SendCan(Z1MotorID, "1VE1" + "\r");
            Can.SendCan(Z1MotorID, "1DI-" + z1distance + "\r");
            Can.SendCan(Z1MotorID, "1FP" + "\r");
            // WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
        }

        public static void Z1DownDistanceWithLiquid(int z1distance)
        {
            int loopnum = 2;
            do
            {
                if (loopnum != 2) //初次进来不用
                {
                    Z1MotorStatus = 0;
                    Z1ReturnToZero();
                    WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
                    Can.SendCan(Z1MotorID, "1IQ" + "\r");
                }
                if (loopnum == 0)
                {
                    // break; //
                    //ServiceProvider.VariableClass.PressButton = "弹框";

                    //表示两次都未检测到液面
                    string dispLiquidErr = "未检测到液面，添加试剂后重新检测请点击“Retry”" + "\r"
                                          + "取消此反应请点击“Abort”" + "\r" +
                                            "忽略请点击“Ignore”";
                    DialogResult dr;
                    dr = MessageBox.Show(dispLiquidErr, "液面探测报警", MessageBoxButtons.AbortRetryIgnore);
                    //string dr = ServiceProvider.VariableClass.PressButton;
                    if (dr == DialogResult.Abort)
                    {
                        //从列表中将此条反应移除
                        break;//退出 继续下面的流程
                    }
                    else if (dr == DialogResult.Retry)
                    {
                        loopnum = 2;
                    }
                    else if (dr == DialogResult.Ignore)
                    {
                        break;//退出 继续下面的流程
                    }
                }
                //if (loopnum == 1)
                //{
                //    Can.SendCan(65, "1IF1050" + "\r");
                //}

                Can.SendCan(Z1MotorID, "1IC15" + "\r");//开启页面探测
                //Can.SendCan(65, "1IF2100" + "\r");   //设置试剂针的灵敏度   
                //Can.SendCan(65, "1IF1050" + "\r");
                if (loopnum == 2)
                {
                    //Can
                    // Can.SendCan(65, "1IF1800" + "\r");  //第一次下去让它
                    // Thread.Sleep(50);//.SendCan(65, "1IF1420" + "\r");
                    Z1MotorStatus = 0;
                    Z1DownDistance(z1distance + 2000);
                    WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
                }
                else
                {
                    Can.SendCan(65, "1IF1340" + "\r");  //第2次下去让它                  
                    Z1MotorStatus = 0;
                    Z1DownDistance(z1distance + 2000);
                    WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
                    Can.SendCan(65, "1IF1999" + "\r");
                }

                Can.SendCan(Z1MotorID, "1DE200" + "\r");
                Can.SendCan(Z1MotorID, "1IC16" + "\r"); //关闭页面探测

                loopnum--;

                if (Z1MotorStatus == 3)
                {
                    //表示两次都未检测到液面
                    string dispLiquidErr = "防撞响应继续请点击“YES”" + "\r"
                                          + "退出请点击“NO”";
                    DialogResult dr;
                    dr = MessageBox.Show(dispLiquidErr, "液面探测报警", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Abort)
                    {
                        //从列表中将此条反应移除
                        break;//退出 继续下面的流程
                    }
                    else if (dr == DialogResult.Yes)
                    {
                        break;//退出 继续下面的流程

                    }
                    else if (dr == DialogResult.No)
                    {
                        //移除本条反应的相关操作
                        break;//退出 继续下面的流程
                    }
                }

            } while (Z1MotorStatus == 1);
            //     Can.SendCan(65, "1IF1999" + "\r");
        }
        public static void Z1DownDistanceWithLiquid2(int z1distance, int count)
        {
            int loopnum = 2;
            do
            {
                if (loopnum != 2) //初次进来不用
                {
                    Z1MotorStatus = 0;
                    Z1ReturnToZero();
                    WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
                    Can.SendCan(Z1MotorID, "1IQ" + "\r");
                }
                if (loopnum == 0)
                {
                    //表示两次都未检测到液面
                    string dispLiquidErr = "未检测到液面，添加试剂后重新检测请点击“Retry”" + "\r"
                                          + "取消此反应请点击“Abort”" + "\r" +
                                            "忽略请点击“Ignore”";
                    DialogResult dr;
                    dr = MessageBox.Show(dispLiquidErr, "液面探测报警", MessageBoxButtons.AbortRetryIgnore);
                    if (dr == DialogResult.Abort)
                    {
                        //从列表中将此条反应移除
                        break;//退出 继续下面的流程
                    }
                    else if (dr == DialogResult.Retry)
                    {
                        loopnum = 2;
                    }
                    else if (dr == DialogResult.Ignore)
                    {
                        break;//退出 继续下面的流程
                    }
                }

                Can.SendCan(Z1MotorID, "1IC15" + "\r");//开启页面探测
                Thread.Sleep(50);

                if (loopnum == 2)
                {
                    //Can.SendCan(65, "1IF1450" + "\r");
                    Z1MotorStatus = 0;
                    Z1DownDistance(z1distance);
                    WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
                }
                else if (loopnum == 1)
                {

                    Z1MotorStatus = 0;
                    Z1DownDistance(z1distance - 2000);
                    WaitStatus(Z1MotorID, ref Z1MotorStatus); //判断Z1结束的
                    //Z1电机2次下降的速度设置减慢
                    Z1MotorStatus = 0;
                    Z1DownDistance2(z1distance);
                    WaitStatus(Z1MotorID, ref Z1MotorStatus);//判断Z1结束的
                }

                Can.SendCan(Z1MotorID, "1DE200" + "\r");
                Can.SendCan(Z1MotorID, "1IC26" + "\r"); //关闭页面探测

                loopnum--;

                if (Z1MotorStatus == 3)
                {
                    //表示两次都未检测到液面
                    string dispLiquidErr = "防撞响应继续请点击“YES”" + "\r"
                                          + "退出请点击“NO”";
                    DialogResult dr;
                    dr = MessageBox.Show(dispLiquidErr, "液面探测报警", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Abort)
                    {
                        //从列表中将此条反应移除
                        break;//退出 继续下面的流程
                    }
                    else if (dr == DialogResult.Yes)
                    {
                        break;//退出 继续下面的流程

                    }
                    else if (dr == DialogResult.No)
                    {
                        //移除本条反应的相关操作
                        break;//退出 继续下面的流程
                    }
                }

            } while (Z1MotorStatus == 1);
        }


        public static void Z1_Z2ClearAreaDownDistance(int clearDistance)
        {

            Can.SendCan(Z1MotorID, "1VE9.5" + "\r");
            Can.SendCan(Z1MotorID, "1DI-" + clearDistance + "\r");
            Can.SendCan(Z1MotorID, "1FP" + "\r");

            Can.SendCan(Z2MotorID, "2VE9.5" + "\r");
            Can.SendCan(Z2MotorID, "2DI-" + clearDistance + "\r");
            Can.SendCan(Z2MotorID, "2FP" + "\r");

        }


        public static void Z2DownDistance(int z2distance)
        {
            Can.SendCan(Z2MotorID, "2DE500" + "\r");
            Can.SendCan(Z2MotorID, "2VE9.5" + "\r");
            Can.SendCan(Z2MotorID, "2DI-" + z2distance + "\r");
            Can.SendCan(Z2MotorID, "2FP" + "\r");
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成

        }
        public static void Z2DownDistanceWithLiquid(int z2distance)
        {
            int loopnum = 2;
            do
            {
                if (loopnum != 2) //初次进来不用
                {
                    Z2MotorStatus = 0;
                    Z2ReturnToZero();
                    WaitStatus(Z2MotorID, ref Z2MotorStatus);//判断Z2结束的
                    Can.SendCan(Z2MotorID, "2IQ" + "\r");
                }
                if (loopnum == 0)
                {
                    // break;
                    //表示两次都未检测到液面
                    string dispLiquidErr = "试剂臂未检测到液面，添加试剂后重新检测请点击“Retry”" + "\r"
                                          + "取消此反应请点击“Abort”" + "\r" +
                                            "忽略请点击“Ignore”";
                    DialogResult dr;
                    dr = MessageBox.Show(dispLiquidErr, "试剂臂液面探测报警", MessageBoxButtons.AbortRetryIgnore);
                    if (dr == DialogResult.Abort)
                    {
                        //从列表中将此条反应移除
                        break;//退出 继续下面的流程
                    }
                    else if (dr == DialogResult.Retry)
                    {
                        loopnum = 2;
                    }
                    else if (dr == DialogResult.Ignore)
                    {
                        break;//退出 继续下面的流程
                    }
                }


                Can.SendCan(Z2MotorID, "2IC25" + "\r");//开启页面探测
                Thread.Sleep(50);
                Z2MotorStatus = 0;
                Z2DownDistance(z2distance);
                WaitStatus(Z2MotorID, ref Z2MotorStatus);//判断Z1结束的

                Can.SendCan(Z2MotorID, "2DE200" + "\r");
                Can.SendCan(Z2MotorID, "2IC26" + "\r"); //关闭页面探测



                loopnum--;

                if (Z2MotorStatus == 3)
                {
                    //表示两次都未检测到液面
                    string dispLiquidErr = "防撞响应继续请点击“YES”" + "\r"
                                          + "退出请点击“NO”";
                    DialogResult dr;
                    dr = MessageBox.Show(dispLiquidErr, "液面探测报警", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Abort)
                    {
                        //从列表中将此条反应移除
                        break;//退出 继续下面的流程
                    }
                    else if (dr == DialogResult.Yes)
                    {
                        break;//退出 继续下面的流程

                    }
                    else if (dr == DialogResult.No)
                    {
                        //移除本条反应的相关操作
                        break;//退出 继续下面的流程
                    }
                }

            } while (Z2MotorStatus == 1);



        }
        /// <summary>
        /// z1在检测区下移的高度
        /// </summary>
        /// <param name="z1distance"></param>
        public static void Z1DownDistanceAtDetectArea(int zDetectDistance)
        {
            Can.SendCan(Z1MotorID, "1VE9.5" + "\r");
            Can.SendCan(Z1MotorID, "1DI-" + zDetectDistance + "\r");
            Can.SendCan(Z1MotorID, "1FP" + "\r");
        }


        /// <summary>
        /// Z2在检测区下移的高度
        /// </summary>
        /// <param name="z2distance"></param>
        public static void Z2DownDistanceAtDetectArea(int zDetectDistance)
        {
            Can.SendCan(Z2MotorID, "2VE9.5" + "\r");
            Can.SendCan(Z2MotorID, "2DI-" + zDetectDistance + "\r");
            Can.SendCan(Z2MotorID, "2FP" + "\r");
        }



        public static void Z2DownALittle()
        {


            Can.SendCan(Z1MotorID, "2VE3" + "\r");
            Can.SendCan(Z1MotorID, "2DI-2000" + "\r");
            Can.SendCan(Z1MotorID, "2FP" + "\r");
        }


        public static void resetZ2_Axis()
        {
            Console.WriteLine("Z2轴复位");

            Can.SendCan(Z1MotorID, "2AC25" + "\r");
            Can.SendCan(Z1MotorID, "2DE25" + "\r");
            Can.SendCan(Z1MotorID, "2VE1" + "\r");
            Can.SendCan(Z1MotorID, "2DI10" + "\r");
            Can.SendCan(Z1MotorID, "2SH2H" + "\r");

        }

        /// <summary>
        /// 复位x轴
        /// </summary>
        public static void resetX_Axis()
        {
            Console.WriteLine("x轴已经复位");

            Can.SendCan(XMotorID, "1AC50" + "\r");
            Can.SendCan(XMotorID, "1DE50" + "\r");
            Can.SendCan(XMotorID, "1VE1" + "\r");
            Can.SendCan(XMotorID, "1CC6" + "\r");
            Can.SendCan(XMotorID, "1DI-10" + "\r");
            Can.SendCan(XMotorID, "1SH1H" + "\r");

        }

        public static void X_FirstWalkALittle()
        {
            Can.SendCan(XMotorID, "1VE1" + "\r");
            Can.SendCan(XMotorID, "1DI" + 1000 + "\r");
            Can.SendCan(XMotorID, "1FL" + "\r");
        }

        public static void Y_FirstWalkALittle()
        {
            Can.SendCan(YMotorID, "1VE1" + "\r");
            Can.SendCan(YMotorID, "1DI" + 1000 + "\r");
            Can.SendCan(YMotorID, "1FL" + "\r");
        }
        /// <summary>
        /// 复位Y轴
        /// </summary>
        public static void resetY_Axis()
        {
            Console.WriteLine("y轴已经复位");

            Can.SendCan(YMotorID, "1AC50" + "\r");
            Can.SendCan(YMotorID, "1DE50" + "\r");
            Can.SendCan(YMotorID, "1VE1" + "\r");
            Can.SendCan(YMotorID, "1CC4" + "\r");
            Can.SendCan(YMotorID, "1DI-10" + "\r");
            Can.SendCan(YMotorID, "1SH1H" + "\r");
        }

        public static void Move_X_YArmToTarget(int x_Axis, int y_Axis)
        {
            //my_can.SendCANData(83, "1VE9.5" + "\r");
            //my_can.SendCANData(83, "1DZ" + (offset_x) + "\r");
            //my_can.SendCANData(83, "1FZ" + "\r");
            ////Y轴出
            //my_can.SendCANData(82, "1VE9.5" + "\r");
            //my_can.SendCANData(82, "1DZ" + (offset_y + 20) + "\r");
            //my_can.SendCANData(82, "1FZ" + "\r");
            Can.SendCan(XMotorID, "1VE6" + "\r");
            Can.SendCan(XMotorID, "1DZ" + x_Axis + "\r");
            Can.SendCan(XMotorID, "1FZ" + "\r");

            Can.SendCan(YMotorID, "1VE6" + "\r");
            Can.SendCan(YMotorID, "1DZ" + y_Axis + "\r");
            Can.SendCan(YMotorID, "1FZ" + "\r");

        }


        /// <summary>
        /// 移动臂到样本区
        /// </summary>
        public void MoveSampleNeedleToSample(ReactionCup cup)
        {
            Console.WriteLine("样本针移动到样本区");
        }



        /// <summary>
        /// 移动样本针到样本区
        /// </summary>
        public void MoveSampleNeedleToReagent(ReactionCup cup)
        {
            Console.WriteLine("样本针到试剂区");
        }



        /// <summary>
        /// 移动臂到试剂区
        /// </summary>
        public void MoveReagentNeedleToReagent(ReactionCup cup)
        {
            Console.WriteLine("试剂针移动到试剂区");
        }


        #region //工程师模块操作方法

        public static void ResetZAxisEnginner()
        {
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            resetZ1_Axis(); //复位z1轴
            resetZ2_Axis();//复位Z2轴
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            Z1DownALittle();//Z1下移一段距离
            Z2DownALittle();//Z2下移一段距离
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            resetZ1_Axis(); //复位z1轴
            resetZ2_Axis();//复位Z2轴
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否完成
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            Can.SendCan(Z1MotorID, "1AC200" + "\r");
            Can.SendCan(Z1MotorID, "1DE200" + "\r");
            Can.SendCan(Z2MotorID, "2AC200" + "\r");
            Can.SendCan(Z2MotorID, "2DE200" + "\r");
        }

        //复位ＸＹ轴
        public static void ResetXYEnginner()
        {
            XMotorStatus = 0;
            YMotorStatus = 0;
            resetX_Axis(); //复位X轴
            resetY_Axis(); //复位Y轴
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            XMotorStatus = 0;
            YMotorStatus = 0;
            X_FirstWalkALittle();//X轴出来一段
            Y_FirstWalkALittle();//Y轴出来一段
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            XMotorStatus = 0;
            YMotorStatus = 0;
            resetX_Axis(); //复位X轴
            resetY_Axis(); //复位Y轴
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            //my_can.SendCANData(83, "1IF" + "\r");
            Can.SendCan(XMotorID, "1IF" + "\r");
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            Can.SendCan(YMotorID, "1IF" + "\r");
        }

        //定位用到的方法
        public static void MoveToPositionEnginner(int x_sample, int y_sample)
        {
            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_sample, y_sample);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
        }
        //Z1轴下移
        public static void Z1DownDistanceEnginner(int downDistance)
        {
            Z1MotorStatus = 0;
            Z1DownDistance(downDistance);
        }
        //Z1轴回到零点
        public static void Z1ReturnZeroEnginner()
        {
            Z1MotorStatus = 0;
            Z1ReturnToZero();  //Z2轴回到零点
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z2是否完成
        }

        //Z2轴下移
        public static void Z2DownDistanceEnginner(int downDistance)
        {
            Z2MotorStatus = 0;
            Z2DownDistance(downDistance);
        }
        //Z2轴回到零点
        public static void Z2ReturnZeroEnginner()
        {
            Z2MotorStatus = 0;
            Z2ReturnToZero();  //Z2轴回到零点
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
        }

        //Z1_Z2同时下移
        public static void Z1_Z2DownDistanceEnginner(int downDistance)
        {
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            Z1_Z2ClearAreaDownDistance(downDistance); //Z2和Z1下移一段距离

            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
        }


        //Z1_Z2同时上来
        public static void ReturnZ1_Z2ZeroEnginner()
        {
            Z1MotorStatus = 0;
            Z2MotorStatus = 0;
            Z1ReturnToZero(); //Z1上移到顶点
            Z2ReturnToZero(); //Z2上移到顶点
            WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z1是否结束
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否结束
        }



        //定位样本区的位置
        public static void PositionToSampleEnginner(int position)
        {
            int x_axis = x_Axis_Sample + (position - 1) % 15 * offSampleSet_x;
            int y_axis = y_Axis_Sample + (position - 1) / 15 * offSampleSet_y;

            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_axis, y_axis);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
        }

        //紧急样本的定位
        public static void urgentSampleToPositionEnginner(int position)
        {
            int x_axis = x_Axis_Emergency;
            int y_axis = y_Axis_Emergency + (position - 1) * offEmergencySet_y;

            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_axis, y_axis);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
        }

        //冷试剂区的定位  Z1
        public static void Z1ColdReagentToPositionEnginner(int position)
        {
            if (position > 6)
            {
                int x_Reagent = x_Axis_Reagent + ((position - 1) % 6) * offReagentSet_x;
                int y_Reagent = y_Axis_Reagent + ((position - 1) / 6) * offReagentSet_y - off_Y_SamplerToReagent;

                XMotorStatus = 0;
                YMotorStatus = 0;
                //此处臂运动去吸液体
                Move_X_YArmToTarget(x_Reagent, y_Reagent);//XY轴移动
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            }
            else
            {
                DialogResult dr;
                dr = MessageBox.Show("选择的数字不能小于7！", "警告！！", MessageBoxButtons.YesNo,
                         MessageBoxIcon.Warning);
                if (dr == DialogResult.Yes)
                {
                    return;
                }

            }


        }
        //冷试剂区定位     Z2
        public static void Z2ColdReagentToPositionEnginner(int position)
        {
            int x_Reagent = x_Axis_Reagent + ((position - 1) % 6) * offReagentSet_x;
            int y_Reagent = y_Axis_Reagent + ((position - 1) / 6) * offReagentSet_y;

            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_Reagent, y_Reagent);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

        }


        //常温试剂区的定位  Z1
        public static void Z1OrdinaryReagentToPositionEnginner(int _hole)
        {
            if (_hole > 2)
            {
                int x_R = x_Axis_HotReagent + ((_hole - 1) % 6) * offHotReagent_x;
                int y_R = y_Axis_HotReagent + ((_hole - 1) / 6) * offHotReagent_y;

                XMotorStatus = 0;
                YMotorStatus = 0;
                //此处臂运动去吸液体
                Move_X_YArmToTarget(x_R, y_R);//XY轴移动
                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

            }
            else
            {

                DialogResult dr;
                dr = MessageBox.Show("选择的数字不能小于3！", "警告！！", MessageBoxButtons.YesNo,
                         MessageBoxIcon.Warning);
                if (dr == DialogResult.Yes)
                {
                    return;
                }

            }
        }

        //常温试剂区定位  Z2
        public static void Z2OrdinaryReagentToPositionEnginner(int _hole)
        {
            int x_R = x_Axis_HotReagent + ((_hole - 1) % 6) * offHotReagent_x;
            int y_R = y_Axis_HotReagent + ((_hole - 1) / 6) * offHotReagent_y;

            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_R, y_R);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
        }



        //检测区的定位 Z1
        public static void Z1DetectAreaToPositionEnginner(int position)
        {
            int x_R = x_Axis_Detect + ((position - 1) % 4) * offDetectSet_x;
            int y_R = y_Axis_Detect + ((position - 1) / 4) * offDetectSet_y;

            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_R, y_R);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
        }

        //检测区的定位 Z2
        public static void Z2DetectAreaToPositionEnginner(int position)
        {

            int x_R = x_Axis_Detect + ((position - 1) % 4) * offDetectSet_x;
            int y_R = y_Axis_Detect + ((position - 1) / 4) * offDetectSet_y + off_Y_SamplerToReagent;

            XMotorStatus = 0;
            YMotorStatus = 0;
            //此处臂运动去吸液体
            Move_X_YArmToTarget(x_R, y_R);//XY轴移动
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
        }

        #endregion

        #region  // 初始值的赋值
        public static void InitArmMoveValue(ObservableCollection<LocationPosition> modelList)
        {
            foreach (LocationPosition model in modelList)
            {
                if (model.Place.Equals("检测区"))
                {
                    x_Axis_Detect = model.XAxis;
                    y_Axis_Detect = model.YAxis;
                    offDetectSet_x = model.XOffset;
                    Z1DetectMaxDownDistance = model.Z1Axis;
                    Z2DetectMaxDownDistance = model.Z2Axis;
                }
                if (model.Place.Equals("清洗区"))
                {
                    clearDistance = model.ZAxis;
                    x_Axis_CleanArea = model.XAxis;
                    y_Axis_CleanArea = model.YAxis;
                }
                if (model.Place.Equals("常温试剂"))
                {
                    x_Axis_HotReagent = model.XAxis;
                    y_Axis_HotReagent = model.YAxis;
                    offHotReagent_x = model.XOffset;
                    offHotReagent_y = model.YOffset;
                    Z1HotReagentMaxDownDistance = model.Z1Axis;
                    Z2HotReagentMaxDownDistance = model.Z2Axis;

                }
                if (model.Place.Equals("冷试剂"))
                {
                    x_Axis_Reagent = model.XAxis;
                    y_Axis_Reagent = model.YAxis;
                    offReagentSet_x = model.XOffset;
                    offReagentSet_y = model.YOffset;
                    Z2ReagentMaxDownDistance = model.Z2Axis;
                    Z1ReagentMaxDownDistance = model.Z1Axis;
                }
                if (model.Place.Equals("紧急样本"))
                {
                    x_Axis_Emergency = model.XAxis;
                    y_Axis_Emergency = model.YAxis;
                    offEmergencySet_x = model.XOffset;
                    offEmergencySet_y = model.YOffset;
                    Z1EmergencyMaxDownDistance = model.Z1Axis;

                }
                if (model.Place.Equals("普通样本"))
                {
                    x_Axis_Sample = model.XAxis;
                    y_Axis_Sample = model.YAxis;
                    offSampleSet_x = model.XOffset;
                    offSampleSet_y = model.YOffset;
                    Z1MaxDowndistance = model.Z1Axis;
                }

                if (model.Place.Equals("小车"))
                {
                    DeliveryCupControl.FirstDetectPosition = model.YAxis;
                    DeliveryCupControl.y_OffsetDetect = model.YOffset;
                }
            }
        }

        #endregion

        public static void PumpResetInControl()
        {
            Pump1Status = 0;
            Pump2Status = 0;
            ResetPump1(); //泵1开始复位
            ResetPump2();//泵2开始复位
                         //  ClearNeedles(clearTime);  //开启阀门进行冲洗试剂和样本针
            WaitStatus(Pump1ID, ref Pump1Status);//检查泵1结束
            WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束
        }

        public static void PumpArispAirPower()
        {
            Pump1Status = 0;
            Pump2Status = 0;
            Pump1ToBreatheAir(emptyAsrip);//泵1吸3000空气
            Pump2ToBreatheAir(emptyAsrip);//泵2吸3000空气
            WaitStatus(Pump1ID, ref Pump1Status);//检查泵1结束
            WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束
        }

        //清洗试剂针
        public static void CleanNeedle(int amont)
        {
            int _hole = 0;
            int _Amount = 0;

            int x_R = 0;

            int y_R = 0;

            int z_R = 0;

            foreach (Clipper.Model.ReagentKit r2 in ServiceProvider.ReagentKitVM.ReagentKitList)
            {
                if (r2.ReagentID2 != null)
                {
                    if (r2.ReagentID2.Equals("清洗液A") && r2.loadDate2 > 100)
                    {
                        _hole = r2.holeNumber;
                        break;
                    }
                }
            }

            _Amount = amont;
            if (_hole < 31)
            {   //制冷区
                //通过孔位号 计算 XY轴坐标
                x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;


                y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y - off_Y_SamplerToReagent;

                z_R = Z1ReagentMaxDownDistance;
            }
            else
            {   //常温区
                x_R = x_Axis_HotReagent + ((_hole - 31) % 2) * offHotReagent_x;


                y_R = y_Axis_HotReagent + ((_hole - 31) / 2) * offHotReagent_y - off_Y_SamplerToReagent;

                z_R = Z1HotReagentMaxDownDistance;
            }

            if (true)
            {
                XMotorStatus = 0;
                YMotorStatus = 0;

                //此处臂运动去吸液体
                Move_X_YArmToTarget(x_R, y_R);//XY轴移动

                WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
                WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

                Z1DownDistanceWithLiquid(z_R);

                //此处根据返回的状态 是否需要重新 下降 吸取液体
                Pump1Status = 0;
                Pump1ToBreathLiquid(_Amount);
                WaitStatus(Pump1ID, ref Pump1Status); //检查泵2结束 
                Z1MotorStatus = 0;
                Z1ReturnToZero();  //Z2轴回到零点
                WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z2是否完成
                Can.SendCan(Z1MotorID, "1IQ" + "\r");
            }
            #region  试剂针吸清洗液
            //if (_hole < 31)
            //{   //制冷区
            //    //通过孔位号 计算 XY轴坐标
            //    x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;

            //    y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y;

            //    z_R = Z2ReagentMaxDownDistance;
            //}
            //else
            //{   //常温区
            //    x_R = x_Axis_HotReagent + ((_hole - 31) % 2) * offHotReagent_x;

            //    y_R = y_Axis_HotReagent + ((_hole - 31) / 2) * offHotReagent_y;

            //    z_R = Z2HotReagentMaxDownDistance;
            //}

            //XMotorStatus = 0;
            //YMotorStatus = 0;
            ////Pump2Status = 0;//==========
            //////此处臂运动去吸液体
            ////Pump2ToBreatheAir(emptyAsrip +1000);//泵2再吸3000空气=======
            //Move_X_YArmToTarget(x_R, y_R);//XY轴移动
            //                              // WaitStatus(Pump2ID, ref Pump2Status);   //检查泵2结束 是否可以空吸
            //WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            //WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
            //                                        // _Amount += 1000;//============
            //Z2DownDistanceWithLiquid(z_R);

            ////此处根据返回的状态 是否需要重新 下降 吸取液体
            //Pump2Status = 0;
            //Pump2ToBreathLiquid(_Amount);
            //WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束 

            //Z2MotorStatus = 0;
            //Z2ReturnToZero();  //Z2轴回到零点
            //WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            //Can.SendCan(Z2MotorID, "2IQ" + "\r");
            //Pump2ToBreathLiquid(_Amount + 1000); //再次吸  为了防止有试剂挤出  之前为1500
            #endregion

            //移动到清洗区进行清洗
            // MoveArmToClearArea(0,3000,true);
        }
        public static void CleanNeedleReagent2(int amont)
        {
            int _hole = 0;
            int _Amount = 0;

            int x_R = 0;

            int y_R = 0;

            int z_R = 0;

            foreach (Clipper.Model.ReagentKit r2 in ServiceProvider.ReagentKitVM.ReagentKitList)
            {
                if (r2.ReagentID2 != null)
                {
                    if (r2.ReagentID2.Equals("清洗液A") && r2.loadDate2 > 100)
                    {
                        _hole = r2.holeNumber;
                        break;
                    }
                }
            }

            _Amount = amont;
            //if (_hole < 31)
            //{   //制冷区
            //    //通过孔位号 计算 XY轴坐标
            //    x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;


            //    y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y - off_Y_SamplerToReagent;

            //    z_R = Z1ReagentMaxDownDistance;
            //}
            //else
            //{   //常温区
            //    x_R = x_Axis_HotReagent + ((_hole - 31) % 2) * offHotReagent_x;


            //    y_R = y_Axis_HotReagent + ((_hole - 31) / 2) * offHotReagent_y - off_Y_SamplerToReagent;

            //    z_R = Z1HotReagentMaxDownDistance;
            //}

            //if (true)
            //{
            //    XMotorStatus = 0;
            //    YMotorStatus = 0;

            //    //此处臂运动去吸液体
            //    Move_X_YArmToTarget(x_R, y_R);//XY轴移动

            //    WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            //    WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成

            //    Z1DownDistanceWithLiquid(z_R);

            //    //此处根据返回的状态 是否需要重新 下降 吸取液体
            //    Pump1Status = 0;
            //    Pump1ToBreathLiquid(_Amount);
            //    WaitStatus(Pump1ID, ref Pump1Status); //检查泵2结束 
            //    Z1MotorStatus = 0;
            //    Z1ReturnToZero();  //Z2轴回到零点
            //    WaitStatus(Z1MotorID, ref Z1MotorStatus); //检查Z2是否完成
            //    Can.SendCan(Z1MotorID, "1IQ" + "\r");
            //}
            #region  试剂针吸清洗液
            if (_hole < 31)
            {   //制冷区
                //通过孔位号 计算 XY轴坐标
                x_R = x_Axis_Reagent + ((_hole - 1) % 6) * offReagentSet_x;

                y_R = y_Axis_Reagent + ((_hole - 1) / 6) * offReagentSet_y;

                z_R = Z2ReagentMaxDownDistance;
            }
            else
            {   //常温区
                x_R = x_Axis_HotReagent + ((_hole - 31) % 2) * offHotReagent_x;

                y_R = y_Axis_HotReagent + ((_hole - 31) / 2) * offHotReagent_y;

                z_R = Z2HotReagentMaxDownDistance;
            }

            XMotorStatus = 0;
            YMotorStatus = 0;
            //Pump2Status = 0;//==========
            ////此处臂运动去吸液体
            //Pump2ToBreatheAir(emptyAsrip +1000);//泵2再吸3000空气=======
            Move_X_YArmToTarget(x_R, y_R);//XY轴移动
                                          // WaitStatus(Pump2ID, ref Pump2Status);   //检查泵2结束 是否可以空吸
            WaitStatus(XMotorID, ref XMotorStatus); //检查x轴是否完成
            WaitStatus(YMotorID, ref YMotorStatus); //检查Y轴是否完成
                                                    // _Amount += 1000;//============
            Z2DownDistanceWithLiquid(z_R);

            //此处根据返回的状态 是否需要重新 下降 吸取液体
            Pump2Status = 0;
            Pump2ToBreathLiquid(_Amount);
            WaitStatus(Pump2ID, ref Pump2Status); //检查泵2结束 

            Z2MotorStatus = 0;
            Z2ReturnToZero();  //Z2轴回到零点
            WaitStatus(Z2MotorID, ref Z2MotorStatus); //检查Z2是否完成
            Can.SendCan(Z2MotorID, "2IQ" + "\r");
            //Pump2ToBreathLiquid(_Amount + 1000); //再次吸  为了防止有试剂挤出  之前为1500
            #endregion
            //移动到清洗区进行清洗
            //  MoveArmToClearArea(0,3000);
        }
    }
}
